var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
			hide:true
		}, {
			colkey : "title",
			name : "申请事项"
		},  {
			colkey : "createUser",
			name : "申请人"
		}, {
			colkey : "details",
			name : "详情"
		}, {
			colkey : "reply",
			name : "回复内容"
		}, {
			colkey : "applyTime",
			name : "申请办理时间",
			width : '180px',
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		}, {
			colkey : "status",
			name : "状态",
			width : '90px',
			renderData : function(rowindex,data, rowdata, column) {

				if(data == "Y"){
					return "<label class='label-primary' style='color: #fff;padding: 3px 4px;border-radius: 3px;'>已处理</label>";
				}else if (data == "C"){
					return "<label class='label-danger' style='color: #fff;padding: 3px 4px;border-radius: 3px;'>未处理</label>";
				}else if(data == "R"){
					return "<label class='label-info' style='color: #fff;padding: 3px 4px;border-radius: 3px;'>已回复</label>"
				}else {
					return "<label class='label-grey' style='color: #fff;padding: 3px 4px;border-radius: 3px;'>已关闭</label>"
				}
			}
		}],
		jsonUrl : rootPath + '/apply/findByPage.shtml',
		checkbox : true,
		serNumber : true
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#handleApply").click("click", function() {
		handleApply();
	});
});
function handleApply() {
	var cbox = grid.selectRow();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox[0].status != "C"){
		layer.alert("该预约已回复。");
		return ;
	}

	var url = rootPath + '/apply/replyUI.shtml?id=' + cbox[0].id;
	pageii = layer.open({
		title : "回复",
		type : 1,
		area : [ "600px", "60%" ],
		content : CommnUtil.ajax(url)
	});
}
function closeApply() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择关闭项！！");
		return;
	}
	layer.confirm('是否关闭？', function(index) {
		var url = rootPath + '/apply/close.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('关闭成功');
			grid.loadData();
		} else {
			layer.msg('关闭失败');
		}
	});
}